/**
 * @author drj
 * @date 2021-12-09 13:20
     used to update the cache resources according to specific .json
     eggjs server
 */

// import axios from "axios";

function refreshCache(){
    let inp = document.querySelector('#cacheInp')
    let json = inp.value
    //console.log(json)
    let reg= /.+.json$/
    //console.log(reg.test(json));
    if(!reg.test(json)){
        alert('json格式不正确 请重新输入')
        return
    }
    updateRemoteCache(json)
}

function updateRemoteCache(json){
    console.log('update cache...')
    let confirmMsg = confirm('要更新缓存吗？')
    if(!confirmMsg){
        return console.log('更新中止')
    }
    alert('点击确定以开始更新。该过程耗时较长，请稍后...')
    json = json || 'cache_skiing.json'
    //console.log(json)
    document.querySelector('#cacheBtn').disabled = true
    // let url = 'http://10.28.185.102:5001/updateCache'
    let url = 'http://127.0.0.1:5001/updateCache'
    axios.post(url,
        {jsonFile:json}
            )
        .then(res=>{
        console.log(res.data);
        if(res.data.status == -1){
            alert(`${res.data.msg}`)
        }else{
            confirm('缓存资源更新完成 :)')
        }
        document.querySelector('#cacheBtn').disabled = false
    }).catch(e=>{
        console.log('发生错误了',e)
    })
}
